package licode.unisop.log.service.adapter.controller;

import licode.unisop.log.client.dto.AuditLogDTO;
import licode.unisop.log.client.dto.CallingLogDTO;
import licode.unisop.log.client.dto.LoginLogDTO;
import licode.unisop.log.client.req.AuditLogIn;
import licode.unisop.log.client.req.CallingLogIn;
import licode.unisop.log.client.req.LoginLogIn;
import licode.unisop.log.service.application.executor.LogLogsExecutor;
import licode.unisop.unilite.dp.PageData;
import licode.unisop.unilite.result.UniReturnResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 适配RESTFUL接口访问，处理用户信息的查询（这里需要做权限控制）
 * 只有拥有user-admin角色的用户才有权限获取用户信息
 *
 * @author WR
 */
@UniReturnResult
@RestController
@RequestMapping("/auth-log/api/v1/query")
public class LogsQueryController extends BaseController {
    @Resource
    private LogLogsExecutor logLogsExecutor;

    @PostMapping("/audit/list")
    public PageData<AuditLogDTO> auditList(@RequestBody AuditLogIn req) {
        if (!isPlatformValid()) {
            return null;
        }
        return logLogsExecutor.auditList(req);
    }

    @PostMapping("/call-api/list")
    public PageData<CallingLogDTO> callApiList(@RequestBody CallingLogIn req) {
        if (!isPlatformValid()) {
            return null;
        }
        return logLogsExecutor.callApiList(req);
    }

    @PostMapping("/login/list")
    public PageData<LoginLogDTO> loginList(@RequestBody LoginLogIn req) {
        if (!isPlatformValid()) {
            return null;
        }
        return logLogsExecutor.loginList(req);
    }
}
